package view;

import java.util.Date;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.validation.constraints.Min;

import org.primefaces.context.RequestContext;

import controller.EmployeeController;
import controller.SalesCardController;
import entity.Commissioned;
import entity.Employee;
import entity.SalesCard;
@ManagedBean
public class AddSalesCard {
	@Inject SalesCardController controller;
	@Inject EmployeeController employeeController;
	private Date date;
	@Min(0)
	private float amount;
	public Date getDate() {
		return date;
	}
	public void setDate(Date date) {
		this.date = date;
	}
	public float getAmount() {
		return amount;
	}
	public void setAmount(float amount) {
		this.amount = amount;
	}
	public String AddNewSalesCard(Employee employee){
		SalesCard card=controller.RegisterNewSalesCard(date, amount, (Commissioned)employee);
		if(card==null){
			RequestContext.getCurrentInstance().execute("PF('dialogNo').show();");
		}else {
			RequestContext.getCurrentInstance().execute("PF('dialogYes').show();");
		}
		return null;
	}
	
	
	
}
